Skip to content

Let an empty body satisfy a body assertion - #79

Merged
korya merged 1 commit into
masterfrom
korya-fix-empty-body-assertions
Aug 8, 2026
Merged

Let an empty body satisfy a body assertion#79
korya merged 1 commit into
masterfrom
korya-fix-empty-body-assertions

Conversation

@korya

@korya korya commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Problem

--assert-body-eq '' could never pass, and the failure said so in a way that refuted itself.

Both --assert-body-eq and --assert-body checked whether the body was empty before checking what had been asked of them:

$ http-assert --assert-body-eq '' http://…/empty     # a 204
- body: expected "", missing

The empty string is not missing — it is exactly what was asked for. So a 204 No Content could not be asserted to have the body a 204 is defined to have.

--assert-body has the same shape, which makes every pattern that legitimately matches an empty body unreachable: ^$, .*, \A\z and the empty pattern all fail against a 204 no matter what the response is.

Solution

Let the comparison decide the verdict, and keep the guard for what it was actually good at.

"missing" reads better than got "" when content was expected and none arrived — that is a genuine improvement to the failure message, and it is worth keeping. It just had no business running before the comparison. It now runs inside the failure branch:

$ http-assert --assert-body-eq '' http://…/empty
[+] PASSED 1ms

$ http-assert --assert-body-eq 'value' http://…/empty
- body: expected "value", missing        ← wording preserved

$ http-assert --assert-body-eq '' http://…/ok
- body: expected "", got "{\"status\":\"success\"}"

The inverse still fails, so this is not "stopped checking dressed up as fixed".

Other Changes

TestKnownIssue22EmptyBodyEqualsNeverPasses is deleted and replaced by TestE2EAssertEmptyBody, which covers both directions: the expectations an empty body now satisfies, and the ones it still must not.

Unit coverage adds the four patterns an empty body legitimately matches, both an empty and a nil BodyBytes (a 204 produces the latter), and a check that the "missing" wording survived. The existing table needed no changes — empty-body-versus-"value" still reports exactly what it did before, which is the evidence the message was preserved rather than sacrificed.

No README change: nothing in it described the broken behaviour, so there is nothing to correct.

There are no screenshots because there is no rendered UI; this tool's user-visible surface is terminal output, shown inline above.

Closes #22

Related:

🤖 Generated with Claude Code

https://claude.ai/code/session_019EMMhgmTkbzAsmeNy97PrP

--assert-body-eq '' could never pass, and neither could --assert-body
with a pattern that matches the empty string. Both checked whether the
body was empty before checking what had been asked of it:

    $ http-assert --assert-body-eq '' http://…/empty   # a 204
    - body: expected "", missing

The message refutes itself -- the empty string is not missing, it is
what was asked for -- and a 204 could not be asserted to have the body
a 204 is defined to have. `^$`, `.*` and `\A\z` were unreachable for the
same reason.

The guard exists to word the failure well: "missing" reads better than
`got ""` when content was expected and none arrived. That is a wording
choice, and it had been deciding the verdict. It now runs inside the
failure branch, so the message survives and the comparison is what
decides.

Closes #22

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019EMMhgmTkbzAsmeNy97PrP
@korya
korya marked this pull request as ready for review August 8, 2026 13:11
@korya
korya merged commit 11df18b into master Aug 8, 2026
8 checks passed
@korya
korya deleted the korya-fix-empty-body-assertions branch August 8, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--assert-body-eq "" can never pass

1 participant